<?php

namespace app\xwam\controller;

/**
 * Description of SystemConfController
 *
 * @since 1.0 <2015-10-20> SoChishun <14507247@qq.com> Added.
 * @since 2.0 2016-6-15 SoChishun Config拆分为SystemConf和CustomConf
 * @since 2.1 2016-8-22 SoChishun SystemConf重命名为SysSystemDict
 */
class SysSystemDictController extends AppbaseController {

    function conf_list_search() {
        $search = I('param.');
        if ($search['word']) {
            $where['_string'] = sprintf("conf_name like '%s' or title like '%s'", $search['word'], $search['word']);
        }
        // $where['site_id'] = $this->site_id;
        return array('where' => $where, 'search' => $search);
    }

    function conf_list() {
        $asearch = $this->conf_list_search();
        $m_conf = new \app\xwam\model\SystemDictModel();
        $list = $m_conf->selectPaging($page, array('where' => $asearch['where'], 'order' => 'sort, id desc'), array('page_params' => $asearch['search']));
        $this->assign('list', $list);
        $this->assign('page', $page->showBootstrap());
        $this->assign('search', $asearch['search']);
        return view();
    }

    function conf_edit($id = '') {
        $data = array();
        $m_conf = new \app\xwam\model\SystemDictModel();
        if ($id) {
            $data = $m_conf->find($id);
        }
        if (!$data) {
            $data = array('user_name' => $this->userName, 'site_id' => $this->siteId);
        }
        $this->assign('data', $data);
        return view();
    }

    function conf_edit_save() {
        $m_conf = new \app\xwam\model\SystemDictModel();
        $result = $m_conf->saveConf();
        $this->dialogJump($result['status'], $result['info']);
    }

    function conf_delete($id = '') {
        $m_conf = new \app\xwam\model\SystemDictModel();
        $result = $m_conf->removeConf($id);
        $this->ajaxReturn($result);
    }

    function changeStatus($id, $status) {
        $m_conf = new \app\xwam\model\SystemDictModel();
        $this->ajaxReturn($m_conf->changeStatus($id, $status));
    }

    function changeSort($id, $sort) {
        $m_conf = new \app\xwam\model\SystemDictModel();
        $this->ajaxReturn($m_conf->changeSort($id, $sort));
    }

}
